#include <stdio.h>
#include <stdlib.h>

void CopyFile(const char* filePath,const char * destPath)
{
    FILE* fr = fopen(filePath,"r");
    if(!fr)
    {
        printf("文件读取打开失败！\n");
        return;
    }
    FILE* fw = fopen(destPath,"w");
    if(!fw)
    {
        printf("文件写入打开失败！\n");
        fclose(fr);
        return;
    }

    fseek(fr,0,SEEK_END);
    long size = ftell(fr);
    fseek(fr,0,SEEK_SET);

    char chunck[4096] = {0};
    long ReadSize = 0;//已经读取了多少个字节

    while(ReadSize != size)
    {
        long trueSize = size - ReadSize > 4096 ? 4096 : size - ReadSize;
        printf("拷贝了%ld个字节:\n",trueSize);
        fread(chunck,trueSize,1,fr);
        fwrite(chunck,trueSize,1,fw);
        ReadSize += trueSize;
    }

    // char *p = malloc(size);
    // int chumkSize = 4096; //4k
    // if(!p)
    // {
    //     printf("申请内存失败！\n");
    //     fclose(fr);
    //     fclose(fw);
    // }
    //分块传输


    // fread(p,size,1,fr);
    // fwrite(p,size,1,fw);
    fclose(fr);
    fclose(fw);


}

int main()
{
    CopyFile("./new.jpg","./new1.jpg");
    return 0;
}